Python/Python Mcq Set 8 Sample Test,Sample questions

Question:
 Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?

1.[3, 4, 5, 20, 5, 25, 1]

2. [1, 3, 3, 4, 5, 5, 20, 25]

3. [3, 5, 20, 5, 25, 1, 3]

4. [1, 3, 4, 5, 20, 5, 25]

Posted Date:-2021-12-31 05:23:46


Question:
 What will be the output of the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]

1. prints all the vowels in my_string

2.prints all the consonants in my_string

3.prints all characters of my_string that aren’t vowels

4.prints only on executing print(k)

Posted Date:-2021-12-31 06:05:49


Question:
 What will be the output of the following Python code?

a=165
b=sum(list(map(int,str(a))))
print(b)

1.561

2. 5

3.12

4.Syntax error

Posted Date:-2021-12-31 06:02:48


Question:
 What will be the output of the following Python code?

a=["Apple","Ball","Cobra"]
<br class="blank" />a.sort(key=len)
print(a)

1. [‘Apple’, ‘Ball’, ‘Cobra’]

2. [‘Ball’, ‘Apple’, ‘Cobra’]

3. [‘Cobra’, ‘Apple’, ‘Ball’]

4. Invalid syntax for sort()

Posted Date:-2021-12-31 06:04:13


Question:
 What will be the output of the following Python code?

a=[[]]*3
a[1].append(7)
print(a)

1. Syntax error

2. [[7], [7], [7]]

3.[[7], [], []]

4. [[],7, [], []]

Posted Date:-2021-12-31 05:56:37


Question:
 What will be the output of the following Python code?

import copy
a=[10,23,56,[78]]
b=copy.deepcopy(a)
a[3][0]=95
a[1]=34
print(b)

1.[10,34,56,[95]]

2.[10,23,56,[78]]

3.[10,23,56,[95]]

4.[10,34,56,[78]]

Posted Date:-2021-12-31 05:54:56


Question:
 What will be the output of the following Python code?

l1=[10, 20, 30]
l2=[-10, -20, -30]
l3=[x+y for x, y in zip(l1, l2)]

1. Error

2.0

3. [-20, -60, -80]

4.[0, 0, 0]

Posted Date:-2021-12-31 06:13:30


Question:
 What will be the output of the following Python code?

myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
    myList[i - 1] = myList[i]
 
for i in range(0, 6): 
    print(myList[i], end = " ")

1. 2 3 4 5 6 1

2.6 1 2 3 4 5

3. 2 3 4 5 6 6

4. 1 1 2 3 4 5

Posted Date:-2021-12-31 05:25:30


Question:
 Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?

1. [x**-1 for x in [(1, 2, 3)]]

2.[1/x for x in [(1, 2, 3)]]

3. [1/x for x in (1, 2, 3)]

4.error

Posted Date:-2021-12-31 06:09:40


Question:
How many elements are in m?

m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

1. 8

2.12

3.16

4.32

Posted Date:-2021-12-31 05:31:15


Question:
Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]

w="hello"
v=('a', 'e', 'i', 'o', 'u')

1. [x for w in v if x in v]

2. [x for x in w if x in v]

3. [x for x in v if w in v]

4. [x for v in w for x in w]

Posted Date:-2021-12-31 06:15:41


Question:
To which of the following the “in” operator can be used to check if an item is in it?

1.Lists

2.Dictionary

3. Set

4.All of the mentioned

Posted Date:-2021-12-31 05:28:35


Question:
What is the output of print(k) in the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]
print(k)

1.all characters of my_string that aren’t vowels

2. a list of Nones

3. list of Trues

4. list of Falses

Posted Date:-2021-12-31 06:06:16


Question:
What will be the output of the following Python code snippet?

my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)

1.[(‘HELLO’, 5), (‘WORLD’, 5)]

2. [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]

3.[(‘HELLO WORLD’, 11)]

4.none of the mentioned

Posted Date:-2021-12-31 06:06:44


Question:
What will be the output of the following Python code snippet?

print([i+j for i in "abc" for j in "def"])

1. [‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

2.[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

3. [[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

4. [‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

Posted Date:-2021-12-31 06:08:10


Question:
What will be the output of the following Python code snippet?

print([i.lower() for i in "HELLO"])

1. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

2. ‘hello’

3. [‘hello’]

4.hello

Posted Date:-2021-12-31 06:07:40


Question:
What will be the output of the following Python code snippet?

print([if i%2==0: i; else: i+1; for i in range(4)])

1. [0, 2, 2, 4]

2.[1, 1, 3, 3]

3.error

4. None of the mentioned

Posted Date:-2021-12-31 06:09:07


Question:
What will be the output of the following Python code snippet?

print([[i+j for i in "abc"] for j in "def"])

1. [‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

2.[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

3.[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

4.[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

Posted Date:-2021-12-31 06:08:34


Question:
What will be the output of the following Python code snippet?

x = [i**+1 for i in range(3)]; print(x);

1. [0, 1, 2]

2.[1, 2, 5]

3. error, **+ is not a valid operator

4. error, ‘;’ is not allowed

Posted Date:-2021-12-31 06:07:14


Question:
What will be the output of the following Python code?

>>>list("a#b#c#d".split('#'))

1.[‘a’, ‘b’, ‘c’, ‘d’]

2. [‘a b c d’]

3.[‘a#b#c#d’]

4. [‘abcd’]

Posted Date:-2021-12-31 05:24:43


Question:
What will be the output of the following Python code?

>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2)

1. [1, 3]

2.[4, 3]

3.[1, 4]

4. [1, 3, 4]

Posted Date:-2021-12-31 05:25:54


Question:
What will be the output of the following Python code?

>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

1. [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

2. [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

3.[1, 2, 3, 4, 5, 6, 7, 8, 9]

4.[0, 1, 2, 1, 2, 3, 2, 3, 4]

Posted Date:-2021-12-31 05:30:52


Question:
What will be the output of the following Python code?

a = [1, 5, 7, 9, 9, 1]
<br class="blank" />b=a[0]
<br class="blank" />x= 0
for x in range(1, len(a)):
    if a[x] > b:
        b = a[x]
        b= x
print(b)

1.5

2.3

3.4

4. 0

Posted Date:-2021-12-31 06:03:43


Question:
What will be the output of the following Python code?

a= [1, 2, 3, 4, 5]
for i in range(1, 5):
    a[i-1] = a[i]
for i in range(0, 5): 
    print(a[i],end = " ")

1. 5 5 1 2 3

2.5 1 2 3 4

3. 2 3 4 5 1

4. 2 3 4 5 5

Posted Date:-2021-12-31 06:03:14


Question:
What will be the output of the following Python code?

a="hello"
b=list((x.upper(),len(x)) for x in a)
print(b)

1. [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]

2. [(‘HELLO’, 5)]

3.[(‘H’, 5), (‘E’, 5), (‘L’, 5), (‘L’, 5), (‘O’, 5)]

4.Syntax error

Posted Date:-2021-12-31 05:55:55


Question:
What will be the output of the following Python code?

a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)

1. 10

2.[1,3,5,7]

3.4

4.[1,3,6,10]

Posted Date:-2021-12-31 05:55:25


Question:
What will be the output of the following Python code?

a=[10,23,56,[78]]
b=list(a)
a[3][0]=95
a[1]=34
print(b)

1.[10,34,56,[95]]

2. [10,23,56,[78]]

3.[10,23,56,[95]]

4. [10,34,56,[78]]

Posted Date:-2021-12-31 05:58:29


Question:
What will be the output of the following Python code?

a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)

1. [13, 56, 17, [87], 45, 67]

2. [13, 56, 17, 87, 45, 67]

3. [13, 56, 17, 87,[ 45, 67]]

4.[13, 56, 17, [87], [45, 67]]

Posted Date:-2021-12-31 05:59:45


Question:
What will be the output of the following Python code?

b=[2,3,4,5]
a=list(filter(lambda x:x%2,b))
print(a)

1.[2,4]

2.[ ]

3. [3,5]

4.Invalid arguments for filter function

Posted Date:-2021-12-31 05:57:05


Question:
What will be the output of the following Python code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
 
def ttt(m):
    v = m[0][0]
 
    for row in m:
        for element in row:
           if v < element: v = element
 
    return v
 
print(ttt(data[0]))

1.1

2.2

3.4

4.5

Posted Date:-2021-12-31 05:34:20


Question:
What will be the output of the following Python code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
 
print(data[1][0][0])

1.1

2.2

3.4

4. 5

Posted Date:-2021-12-31 05:33:58


Question:
What will be the output of the following Python code?

def addItem(listParam):
    listParam += [1]
 
mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))

1.1

2. 4

3.5

4.8

Posted Date:-2021-12-31 05:29:18


Question:
What will be the output of the following Python code?

def example(L):
    ''' (list) -> list
    '''
    i = 0
    result = []
    while i < len(L):
        result.append(L[i])
        i = i + 3
    return result

1.Return a list containing every third item from L starting at index 0

2. Return an empty list

3.Return a list containing every third index from L starting at index 0

4.Return a list containing the items from L starting from index 0, omitting every third item

Posted Date:-2021-12-31 05:29:46


Question:
What will be the output of the following Python code?

def f(i, values = []):
    values.append(i)
    return values
 
f(1)
f(2)
v = f(3)
print(v)

1.[1] [2] [3]

2. [1] [1, 2] [1, 2, 3]

3. [1, 2, 3]

4. 1 2 3 4

Posted Date:-2021-12-31 05:27:02


Question:
What will be the output of the following Python code?

def f(values):
    values[0] = 44
 
v = [1, 2, 3]
f(v)
print(v)

1.[1, 44]

2.[1, 2, 3, 44]

3.[44, 2, 3]

4.[1, 2, 3]

Posted Date:-2021-12-31 05:26:17


Question:
What will be the output of the following Python code?

def m(list):
    v = list[0]
    for e in list:
      if v < e: v = e
    return v
 
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
 
for row in values: 
    print(m(row), end = " ")

1. 3 33

2. 1 1

3.5 6

4.5 33

Posted Date:-2021-12-31 05:33:30


Question:
What will be the output of the following Python code?

def unpack(a,b,c,d):
    print(a+d)
x = [1,2,3,4]
unpack(*x)

1.Error

2. [1,4]

3.[5]

4.5

Posted Date:-2021-12-31 06:00:46


Question:
What will be the output of the following Python code?

import math
[str(round(math.pi)) for i in range (1, 6)]

1. [‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’]

2. [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’]

3. [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]

4. [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’]

Posted Date:-2021-12-31 06:14:55


Question:
What will be the output of the following Python code?

l1=[1,2,3]
l2=[4,5,6]
[x*y for x in l1 for y in l2]

1. [4, 8, 12, 5, 10, 15, 6, 12, 18]

2.[4, 10, 18]

3. [4, 5, 6, 8, 10, 12, 12, 15, 18]

4.[18, 12, 6, 15, 10, 5, 12, 8, 4]

Posted Date:-2021-12-31 06:11:50


Question:
What will be the output of the following Python code?

l=[1,2,3,4,5]
[x&1 for x in l]

1. [1, 1, 1, 1, 1]

2.[1, 0, 1, 0, 1]

3. [1, 0, 0, 0, 0]

4. [0, 1, 0, 1, 0]

Posted Date:-2021-12-31 06:11:20


Question:
What will be the output of the following Python code?

list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
 
print(len(list1 + list2))

1. 2

2.4

3.5

4.8

Posted Date:-2021-12-31 05:28:55


Question:
What will be the output of the following Python code?

lst=[3,4,6,1,2]
lst[1:2]=[7,8]
print(lst)

1. [3, 7, 8, 6, 1, 2]

2. Syntax error

3. [3,[7,8],6,1,2]

4. [3,4,6,7,8]

Posted Date:-2021-12-31 05:57:35


Question:
What will be the output of the following Python code?

lst=[[1,2],[3,4]]
print(sum(lst,[]))

1. [[3],[7]]

2.[1,2,3,4]

3.Error

4. [10]

Posted Date:-2021-12-31 06:00:17


Question:
What will be the output of the following Python code?

matrix = [[1, 2, 3, 4],
       [4, 5, 6, 7],
       [8, 9, 10, 11],
       [12, 13, 14, 15]]
 
for i in range(0, 4):
    print(matrix[i][1], end = " ")

1.1 2 3 4

2.4 5 6 7

3.1 3 8 12

4. 2 5 9 13

Posted Date:-2021-12-31 05:33:03


Question:
What will be the output of the following Python code?

myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
    if myList[i] > max:
        max = myList[i]
        indexOfMax = i
 
>>>print(indexOfMax)

1.1

2.2

3.3

4.4

Posted Date:-2021-12-31 05:25:02


Question:
What will be the output of the following Python code?

names1 = ['Amir', 'Bala', 'Chales']
 
if 'amir' in names1:
    print(1)
else:
    print(2)

1. None

2. 1

3. 2

4.error

Posted Date:-2021-12-31 05:27:30


Question:
What will be the output of the following Python code?

names1 = ['Amir', 'Bala', 'Charlie']
names2 = [name.lower() for name in names1]
 
print(names2[2][0])

1. None

2. a

3.b

4.c

Posted Date:-2021-12-31 05:27:51


Question:
What will be the output of the following Python code?

num = ['One', 'Two', 'Three']
for i, x in enumerate(num):
    print('{}: {}'.format(i, x),end=" ")

1. 1: 2: 3:

2.Exception is thrown

3.One Two Three

4.0: One 1: Two 2: Three

Posted Date:-2021-12-31 06:04:42


Question:
What will be the output of the following Python code?

numbers = [1, 2, 3, 4]
 
numbers.append([5,6,7,8])
 
print(len(numbers))

1. 4

2.5

3. 8

4.12

Posted Date:-2021-12-31 05:28:13


Question:
What will be the output of the following Python code?

places = ['Bangalore', 'Mumbai', 'Delhi']
<br class="blank" />places1 = places
places2 = places[:]
<br class="blank" />places1[1]="Pune"
places2[2]="Hyderabad"
print(places)

1.[‘Bangalore’, ‘Pune’, ‘Hyderabad’]

2.[‘Bangalore’, ‘Pune’, ‘Delhi’]

3. [‘Bangalore’, ‘Mumbai’, ‘Delhi’]

4.[‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]

Posted Date:-2021-12-31 06:01:16


Question:
What will be the output of the following Python code?

points = [[1, 2], [3, 1.5], [0.5, 0.5]]
points.sort()
print(points)

1.[[1, 2], [3, 1.5], [0.5, 0.5]]

2.[[3, 1.5], [1, 2], [0.5, 0.5]]

3.[[0.5, 0.5], [1, 2], [3, 1.5]]

4. [[0.5, 0.5], [3, 1.5], [1, 2]]

Posted Date:-2021-12-31 05:34:50


Question:
What will be the output of the following Python code?

s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]

1. Error

2. [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]

3.[PUNE, 4, MUMBAI, 6, DELHI, 5]

4.[(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

Posted Date:-2021-12-31 06:12:56


Question:
What will be the output of the following Python code?

values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
 
for row in values:
    row.sort()
    for element in row:
        print(element, end = " ")
    print()

1. The program prints two rows 3 4 5 1 followed by 33 6 1 2

2. The program prints on row 3 4 5 1 33 6 1 2

3.The program prints two rows 3 4 5 1 followed by 33 6 1 2

4.The program prints two rows 1 3 4 5 followed by 1 2 6 33

Posted Date:-2021-12-31 05:32:32


Question:
What will be the output of the following Python code?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]
 
v = values[0][0]
for lst in values:
    for element in lst:
        if v > element:
            v = element
 
print(v)

1. 1

2. 3

3. 5

4. 6

Posted Date:-2021-12-31 05:32:05


Question:
What will be the output of the following Python code?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]
 
v = values[0][0]
for row in range(0, len(values)):
    for column in range(0, len(values[row])):
        if v < values[row][column]:
            v = values[row][column]
 
print(v)

1.3

2. 5

3.6

4.33

Posted Date:-2021-12-31 05:31:40


Question:
What will be the output of the following Python code?

veggies = ['carrot', 'broccoli', 'potato', 'asparagus']
veggies.insert(veggies.index('broccoli'), 'celery')
print(veggies)

1.[‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] Correct 1.00

2. [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]

3.[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]

4.[‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]

Posted Date:-2021-12-31 05:30:13


Question:
What will be the output of the following Python code?

x=[[1],[2]]
print(" ".join(list(map(str,x))))

1.[1] [2]

2.[49] [50]

3.Syntax error

4.[[1]] [[2]]

Posted Date:-2021-12-31 06:02:24


Question:
What will be the output of the following Python code?
>>>"Welcome to Python".split()

1. [“Welcome”, “to”, “Python”]

2.(“Welcome”, “to”, “Python”)

3. {“Welcome”, “to”, “Python”}

4.“Welcome”, “to”, “Python”

Posted Date:-2021-12-31 05:24:18


Question:
Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].

1.[x**3 for x in l]

2. [x^3 for x in l]

3. [x**3 in l]

4.[x^3 in l]

Posted Date:-2021-12-31 06:14:03


Question:
Write the list comprehension to pick out only negative integers from a given list ‘l’.

1. [x<0 in l]

2. [x for x<0 in l]

3. [x in l for x<0]

4. [x for x in l if x<0]

Posted Date:-2021-12-31 06:12:21


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!